<?php

	class Db {

		public static $server;
		public static $user;
		public static $password;
		public static $database;
		public static $port;
		public static $link;
		//Savoir si l'on est connect� � une base ou non
		private static $connect;
		

		//Instanciation de la base
		public function __construct() {
			self::$server = _DB_SERVER_;
			self::$user = _DB_USER_;
			self::$password = _DB_PASSWD_;
			self::$database = _DB_NAME_;
			self::$port = _DB_PORT_;
			$this->connect();
		}
		
		
		//Connexion a la base
		public function	connect(){
			$dsn = 'mysql:dbname='.self::$database.';host='.self::$server.';port:'.self::$port.';';
			try {
				self::$link = new PDO($dsn, self::$user, self::$password);
				self::$connect = 1;

			} catch (PDOException $e) {
				echo 'Connexion �chou�e : ' . $e->getMessage();
			}
			return self::$link;
		}
		
		public static function pSQL($string) {
			$retour = '';
			$retour = mysqli_real_escape_string($string);
			$retour = html_entity_decode($string);
			return $retour;
		}

		public static function insertion($string) {
			$string = html_entity_decode($string);
			$string = addslashes($string);
			return $string;
		}
		
		public static function Execute($sql, $retourForeach = false, $db = null) {
			if($retourForeach) {
				$temp = self::$link->query($sql);
				return $temp;
			}
			else {
				self::$link->exec($sql);
				return self::$link->lastInsertId();
			}
		}
	}

?>
